export function setSelectList(data, val) {
  for (let item of data) {
    item.label = item[val.label]
    item.value = item[val.value]
  }
  return data;
}
export function setCascaderList(data, val) {
  for (let item of data) {
    item.label = item[val.mt][val.label]
    item.value = item[val.mt][val.value]
    item.children = item[val.child]
    if (item[val.child] && item[val.child].length) {
      setCascaderList(item[val.child], val)
    }
  }
}
const plusZero = (value) => {
  return value < 10 ? "0" + value : value;
}
export function formatDate(value, hasTime) {
  if (!value) return "";
  if (typeof value === 'string') {
    value = value.replace(/\-/g, "/");
  }
  value = new Date(value);
  let result = "";
  let year = value.getFullYear();
  let month = value.getMonth() + 1;
  let day = value.getDate();

  month = plusZero(month);
  day = plusZero(day);

  result = year + "-" + month + "-" + day;

  if (hasTime) {
    let hour = value.getHours();
    let minute = value.getMinutes();
    let seconds = value.getSeconds();
    hour = plusZero(hour);
    minute = plusZero(minute);
    seconds = plusZero(seconds)
    result += " " + hour + ":" + minute + ":" + seconds
  }

  return result;
}
export function getPuduct(data, val) {
  let newArray = [];
  for (let item of data) {
    for (let todo of item[val.child]) {
      newArray.push({
        "productId": todo[val.getParam[0]],
        "skuId": todo[val.getParam[1]],
        "promotionPrice": todo[val.getParam[2]],
        "isMustBuy": item[val.getParam[3]]
      })
    }
  }
  return newArray;
}
export function getGift(data, val) {
  let newArray = [];
  for (let item of data) {
    for (let todo of item[val.child]) {
      newArray.push({
        "productId": todo[val.getParam[0]],
        "skuId": todo[val.getParam[1]],
        "quantity": 1,
        "returnPrice": todo[val.getParam[3]],
        "productSn": todo[val.getParam[4]],
        "skuSn": todo[val.getParam[5]],
        "groups": '1'
      })
    }
  }
  return newArray;
}
